/* xpath_util.js -- Helper functions for XPath

  Copyright (C) 2007 by Lukas Loehrer
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

  Author: loehrerl [at] gmx [dot] net
*/

/* Example: lists all the frames and iframes in page
 var result = queryForSnapshot(someDOMNode, "//frame|//iframe");
 for (var i = 0; i < result.snapshotLength; ++i) {
        var frame = result.snapshotItem(i)
		}
*/

const nsIDOMXPathResult = Components.interfaces.nsIDOMXPathResult;

// Should not be needed for HTML
function createNSResolver(doc, contextNode) {
	contextNode = contextNode || doc;
	var nsResolver = doc.createNSResolver( contextNode.ownerDocument == null ? contextNode.documentElement : contextNode.ownerDocument.documentElement );
	return nsResolver;
}

function simpleQuery(aDocument, aExpression, aContextNode, aReturnType) {
	aReturnType = aReturnType || nsIDOMXPathResult.ANY_TYPE;
	aContextNode = aContextNode || aDocument;
	//var nsResolver = createNSResolver(aDocument, aContextNode);
	var result = aDocument.evaluate(aExpression, aContextNode, null, aReturnType, null);
return result;
}

function queryForSnapshot(aNode, aQuery) {
	return simpleQuery(aNode.ownerDocument, aQuery,  aNode, nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
}

	// {{{ Emacs local variables

// local variables:
// folded-file: t
// end:

// }}}
